Change in openvpn[master]: tests/unit_tests: Port to cmocka 2.0.0 API
A message that is not in the archive (sent off-list or not yet received): gerrit.1765989193000.Ifb6594700db71d219643a29c581099c778bcbbc6@...2715...
Attention is currently required from: plaisthos.
Hello plaisthos,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email
to review the following change.
Change subject: tests/unit_tests: Port to cmocka 2.0.0 API
......................................................................
tests/unit_tests: Port to cmocka 2.0.0 API
But add compat layer so that we can still build
against older versions of cmocka. Mostly this is
trivial but the custom check function changed its
prototype, so that requires some more work.
---
M CMakeLists.txt
M config.h.cmake.in
M configure.ac
M tests/unit_tests/openvpn/test_common.h
M tests/unit_tests/openvpn/test_options_parse.c
M tests/unit_tests/openvpn/test_push_update_msg.c
M tests/unit_tests/openvpn/test_user_pass.c
7 files changed, 79 insertions(+), 46 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/49/1449/1
CMakeLists.txt +12 -8
@@ -379,6 +379,18 @@ ) set(HAVE_CONFIG_VERSION_H YES) +if (BUILD_TESTING) + find_package(cmocka CONFIG) + if (TARGET cmocka::cmocka) + set(CMOCKA_LIBRARIES cmocka::cmocka) + else () + pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) + set(CMOCKA_LIBRARIES PkgConfig::cmocka) + endif () + set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES}) + check_include_files(cmocka_version.h HAVE_CMOCKA_VERSION_H) +endif () + configure_file(config.h.cmake.in config.h) configure_file(include/openvpn-plugin.h.in openvpn-plugin.h) # TODO we should remove the need for this, and always include config.h
@@ -636,14 +648,6 @@ option(UT_ALLOW_BIG_ALLOC "Allow unit-tests to use > 1 GB of memory" ON) if (BUILD_TESTING) - find_package(cmocka CONFIG) - if (TARGET cmocka::cmocka) - set(CMOCKA_LIBRARIES cmocka::cmocka) - else () - pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) - set(CMOCKA_LIBRARIES PkgConfig::cmocka) - endif () - set(unit_tests "test_argv" "test_auth_token"
config.h.cmake.in +3 -0
@@ -86,6 +86,9 @@ /* git version information in config-version.h */ #cmakedefine HAVE_CONFIG_VERSION_H +/* cmocka version information available in cmocka_version.h (>= 2.0.0) */ +#cmakedefine HAVE_CMOCKA_VERSION_H + /* Define to 1 if you have the `daemon' function. */ #cmakedefine HAVE_DAEMON
configure.ac +10 -1
@@ -1415,7 +1415,16 @@ [have_cmocka="yes"], [AC_MSG_WARN([cmocka.pc not found on the system using pkg-config ${pkg_config_found}. Unit tests disabled])] ) -AM_CONDITIONAL([ENABLE_UNITTESTS], [test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes" ]) +AM_CONDITIONAL([ENABLE_UNITTESTS], [false]) +if test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes"; then + AM_CONDITIONAL([ENABLE_UNITTESTS], [true]) + + saved_CFLAGS="${CFLAGS}" + CFLAGS="${CFLAGS} ${LZO_CFLAGS}" + # detect cmocka < 2.0.0 that had no cmocka_version.h + AC_CHECK_HEADERS([cmocka_version.h]) + CFLAGS="${saved_CFLAGS}" +fi AC_SUBST([ENABLE_UNITTESTS]) TEST_LDFLAGS="${OPTIONAL_CRYPTO_LIBS} ${OPTIONAL_PKCS11_HELPER_LIBS} ${OPTIONAL_LIBCAPNG_LIBS}"
tests/unit_tests/openvpn/test_common.h +21 -0
@@ -24,6 +24,27 @@#include <setjmp.h> #include <cmocka.h> +/* Do we use cmocka < 2.0.0? */ +#ifndef HAVE_CMOCKA_VERSION_H +#define HAVE_OLD_CMOCKA_API 1 +/* compat with various versions of cmocka.h +* Older versions have LargestIntegralType. Newer +* versions use uintmax_t. But LargestIntegralType +* is not guaranteed to be equal to uintmax_t, so +* we can't use that unconditionally. So we only use +* it if cmocka.h does not define LargestIntegralType. +*/ +#ifndef LargestIntegralType +#define LargestIntegralType uintmax_t +#endif +/* redefine 2.x API in terms of 1.x API */ +#define CMockaValueData LargestIntegralType +#define check_expected_uint check_expected +#define expect_uint_value expect_value +#define expect_check_data expect_check +#define cast_ptr_to_cmocka_value (x) (x) +#endif +/** * Sets up the environment for unit tests like making both stderr and stdout * non-buffered to avoid messages getting lost if the program exits early.
tests/unit_tests/openvpn/test_options_parse.c +31 -35
103 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +1 -1
@@ -171,7 +171,7 @@bool send_control_channel_string (struct context *c,const char *str,msglvl_t msglevel) { -check_expected (str); +check_expected_ptr (str);return true; }
tests/unit_tests/openvpn/test_user_pass.c +1 -1
@@ -52,7 +52,7 @@/* Loop through configured query_user slots */ for (int i =0 ; i <QUERY_USER_NUMSLOTS && query_user[i].response !=NULL ; i++) { -check_expected (query_user[i].prompt); +check_expected_ptr (query_user[i].prompt); strncpy(query_user[i].response, mock_ptr_type(char *), query_user[i].response_len); }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ifb6594700db71d219643a29c581099c778bcbbc6
Gerrit-Change-Number: 1449
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Attention is currently required from: plaisthos.
Hello plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email
to look at the new patch set (#2).
Change subject: tests/unit_tests: Port to cmocka 2.0.0 API
......................................................................
tests/unit_tests: Port to cmocka 2.0.0 API
But add compat layer so that we can still build
against older versions of cmocka. Mostly this is
trivial but the custom check function changed its
prototype, so that requires some more work.
---
M CMakeLists.txt
M config.h.cmake.in
M configure.ac
M tests/unit_tests/openvpn/test_common.h
M tests/unit_tests/openvpn/test_options_parse.c
M tests/unit_tests/openvpn/test_push_update_msg.c
M tests/unit_tests/openvpn/test_user_pass.c
7 files changed, 79 insertions(+), 46 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/49/1449/2
CMakeLists.txt +12 -8
@@ -379,6 +379,18 @@ ) set(HAVE_CONFIG_VERSION_H YES) +if (BUILD_TESTING) + find_package(cmocka CONFIG) + if (TARGET cmocka::cmocka) + set(CMOCKA_LIBRARIES cmocka::cmocka) + else () + pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) + set(CMOCKA_LIBRARIES PkgConfig::cmocka) + endif () + set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES}) + check_include_files(cmocka_version.h HAVE_CMOCKA_VERSION_H) +endif () + configure_file(config.h.cmake.in config.h) configure_file(include/openvpn-plugin.h.in openvpn-plugin.h) # TODO we should remove the need for this, and always include config.h
@@ -636,14 +648,6 @@ option(UT_ALLOW_BIG_ALLOC "Allow unit-tests to use > 1 GB of memory" ON) if (BUILD_TESTING) - find_package(cmocka CONFIG) - if (TARGET cmocka::cmocka) - set(CMOCKA_LIBRARIES cmocka::cmocka) - else () - pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) - set(CMOCKA_LIBRARIES PkgConfig::cmocka) - endif () - set(unit_tests "test_argv" "test_auth_token"
config.h.cmake.in +3 -0
@@ -86,6 +86,9 @@ /* git version information in config-version.h */ #cmakedefine HAVE_CONFIG_VERSION_H +/* cmocka version information available in cmocka_version.h (>= 2.0.0) */ +#cmakedefine HAVE_CMOCKA_VERSION_H + /* Define to 1 if you have the `daemon' function. */ #cmakedefine HAVE_DAEMON
configure.ac +10 -1
@@ -1415,7 +1415,16 @@ [have_cmocka="yes"], [AC_MSG_WARN([cmocka.pc not found on the system using pkg-config ${pkg_config_found}. Unit tests disabled])] ) -AM_CONDITIONAL([ENABLE_UNITTESTS], [test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes" ]) +AM_CONDITIONAL([ENABLE_UNITTESTS], [false]) +if test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes"; then + AM_CONDITIONAL([ENABLE_UNITTESTS], [true]) + + saved_CFLAGS="${CFLAGS}" + CFLAGS="${CFLAGS} ${LZO_CFLAGS}" + # detect cmocka < 2.0.0 that had no cmocka_version.h + AC_CHECK_HEADERS([cmocka_version.h]) + CFLAGS="${saved_CFLAGS}" +fi AC_SUBST([ENABLE_UNITTESTS]) TEST_LDFLAGS="${OPTIONAL_CRYPTO_LIBS} ${OPTIONAL_PKCS11_HELPER_LIBS} ${OPTIONAL_LIBCAPNG_LIBS}"
tests/unit_tests/openvpn/test_common.h +21 -0
@@ -24,6 +24,27 @@#include <setjmp.h> #include <cmocka.h> +/* Do we use cmocka < 2.0.0? */ +#ifndef HAVE_CMOCKA_VERSION_H +#define HAVE_OLD_CMOCKA_API 1 +/* compat with various versions of cmocka.h +* Older versions have LargestIntegralType. Newer +* versions use uintmax_t. But LargestIntegralType +* is not guaranteed to be equal to uintmax_t, so +* we can't use that unconditionally. So we only use +* it if cmocka.h does not define LargestIntegralType. +*/ +#ifndef LargestIntegralType +#define LargestIntegralType uintmax_t +#endif +/* redefine 2.x API in terms of 1.x API */ +#define CMockaValueData LargestIntegralType +#define check_expected_uint check_expected +#define expect_uint_value expect_value +#define expect_check_data expect_check +#define cast_ptr_to_cmocka_value (x) (x) +#endif +/** * Sets up the environment for unit tests like making both stderr and stdout * non-buffered to avoid messages getting lost if the program exits early.
tests/unit_tests/openvpn/test_options_parse.c +31 -35
103 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +1 -1
@@ -171,7 +171,7 @@bool send_control_channel_string (struct context *c,const char *str,msglvl_t msglevel) { -check_expected (str); +check_expected_ptr (str);return true; }
tests/unit_tests/openvpn/test_user_pass.c +1 -1
@@ -52,7 +52,7 @@/* Loop through configured query_user slots */ for (int i =0 ; i <QUERY_USER_NUMSLOTS && query_user[i].response !=NULL ; i++) { -check_expected (query_user[i].prompt); +check_expected_ptr (query_user[i].prompt); strncpy(query_user[i].response, mock_ptr_type(char *), query_user[i].response_len); }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ifb6594700db71d219643a29c581099c778bcbbc6
Gerrit-Change-Number: 1449
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Attention is currently required from: plaisthos.
Hello plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email
to look at the new patch set (#3).
Change subject: tests/unit_tests: Port to cmocka 2.0.0 API
......................................................................
tests/unit_tests: Port to cmocka 2.0.0 API
But add compat layer so that we can still build
against older versions of cmocka. Mostly this is
trivial but the custom check function changed its
prototype, so that requires some more work.
---
M CMakeLists.txt
M config.h.cmake.in
M configure.ac
M tests/unit_tests/openvpn/test_common.h
M tests/unit_tests/openvpn/test_options_parse.c
M tests/unit_tests/openvpn/test_push_update_msg.c
M tests/unit_tests/openvpn/test_user_pass.c
7 files changed, 79 insertions(+), 46 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/49/1449/3
CMakeLists.txt +12 -8
@@ -379,6 +379,18 @@ ) set(HAVE_CONFIG_VERSION_H YES) +if (BUILD_TESTING) + find_package(cmocka CONFIG) + if (TARGET cmocka::cmocka) + set(CMOCKA_LIBRARIES cmocka::cmocka) + else () + pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) + set(CMOCKA_LIBRARIES PkgConfig::cmocka) + endif () + set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES}) + check_include_files(cmocka_version.h HAVE_CMOCKA_VERSION_H) +endif () + configure_file(config.h.cmake.in config.h) configure_file(include/openvpn-plugin.h.in openvpn-plugin.h) # TODO we should remove the need for this, and always include config.h
@@ -636,14 +648,6 @@ option(UT_ALLOW_BIG_ALLOC "Allow unit-tests to use > 1 GB of memory" ON) if (BUILD_TESTING) - find_package(cmocka CONFIG) - if (TARGET cmocka::cmocka) - set(CMOCKA_LIBRARIES cmocka::cmocka) - else () - pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) - set(CMOCKA_LIBRARIES PkgConfig::cmocka) - endif () - set(unit_tests "test_argv" "test_auth_token"
config.h.cmake.in +3 -0
@@ -86,6 +86,9 @@ /* git version information in config-version.h */ #cmakedefine HAVE_CONFIG_VERSION_H +/* cmocka version information available in cmocka_version.h (>= 2.0.0) */ +#cmakedefine HAVE_CMOCKA_VERSION_H + /* Define to 1 if you have the `daemon' function. */ #cmakedefine HAVE_DAEMON
configure.ac +10 -1
@@ -1415,7 +1415,16 @@ [have_cmocka="yes"], [AC_MSG_WARN([cmocka.pc not found on the system using pkg-config ${pkg_config_found}. Unit tests disabled])] ) -AM_CONDITIONAL([ENABLE_UNITTESTS], [test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes" ]) +AM_CONDITIONAL([ENABLE_UNITTESTS], [false]) +if test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes"; then + AM_CONDITIONAL([ENABLE_UNITTESTS], [true]) + + saved_CFLAGS="${CFLAGS}" + CFLAGS="${CFLAGS} ${CMOCKA_CFLAGS}" + # detect cmocka < 2.0.0 that had no cmocka_version.h + AC_CHECK_HEADERS([cmocka_version.h]) + CFLAGS="${saved_CFLAGS}" +fi AC_SUBST([ENABLE_UNITTESTS]) TEST_LDFLAGS="${OPTIONAL_CRYPTO_LIBS} ${OPTIONAL_PKCS11_HELPER_LIBS} ${OPTIONAL_LIBCAPNG_LIBS}"
tests/unit_tests/openvpn/test_common.h +21 -0
@@ -24,6 +24,27 @@#include <setjmp.h> #include <cmocka.h> +/* Do we use cmocka < 2.0.0? */ +#ifndef HAVE_CMOCKA_VERSION_H +#define HAVE_OLD_CMOCKA_API 1 +/* compat with various versions of cmocka.h +* Older versions have LargestIntegralType. Newer +* versions use uintmax_t. But LargestIntegralType +* is not guaranteed to be equal to uintmax_t, so +* we can't use that unconditionally. So we only use +* it if cmocka.h does not define LargestIntegralType. +*/ +#ifndef LargestIntegralType +#define LargestIntegralType uintmax_t +#endif +/* redefine 2.x API in terms of 1.x API */ +#define CMockaValueData LargestIntegralType +#define check_expected_uint check_expected +#define expect_uint_value expect_value +#define expect_check_data expect_check +#define cast_ptr_to_cmocka_value (x) (x) +#endif +/** * Sets up the environment for unit tests like making both stderr and stdout * non-buffered to avoid messages getting lost if the program exits early.
tests/unit_tests/openvpn/test_options_parse.c +31 -35
103 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +1 -1
@@ -171,7 +171,7 @@bool send_control_channel_string (struct context *c,const char *str,msglvl_t msglevel) { -check_expected (str); +check_expected_ptr (str);return true; }
tests/unit_tests/openvpn/test_user_pass.c +1 -1
@@ -52,7 +52,7 @@/* Loop through configured query_user slots */ for (int i =0 ; i <QUERY_USER_NUMSLOTS && query_user[i].response !=NULL ; i++) { -check_expected (query_user[i].prompt); +check_expected_ptr (query_user[i].prompt); strncpy(query_user[i].response, mock_ptr_type(char *), query_user[i].response_len); }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ifb6594700db71d219643a29c581099c778bcbbc6
Gerrit-Change-Number: 1449
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email )
Change subject: tests/unit_tests: Port to cmocka 2.0.0 API
......................................................................
Patch Set 3: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ifb6594700db71d219643a29c581099c778bcbbc6
Gerrit-Change-Number: 1449
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 18 Dec 2025 10:40:19 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
PATCH v3 1/1 tests/unit_tests: Port to cmocka 2.0.0 API
In reply to a message not in the archiveFrom: Frank Lichtenheld <[email protected]...>
But add compat layer so that we can still build
against older versions of cmocka. Mostly this is
trivial but the custom check function changed its
prototype, so that requires some more work.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1449
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1449
This mail reflects revision 3 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
CMakeLists.txt +12 -8
@@ -379,6 +379,18 @@ ) set(HAVE_CONFIG_VERSION_H YES) +if (BUILD_TESTING) + find_package(cmocka CONFIG) + if (TARGET cmocka::cmocka) + set(CMOCKA_LIBRARIES cmocka::cmocka) + else () + pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) + set(CMOCKA_LIBRARIES PkgConfig::cmocka) + endif () + set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES}) + check_include_files(cmocka_version.h HAVE_CMOCKA_VERSION_H) +endif () + configure_file(config.h.cmake.in config.h) configure_file(include/openvpn-plugin.h.in openvpn-plugin.h) # TODO we should remove the need for this, and always include config.h
@@ -636,14 +648,6 @@ option(UT_ALLOW_BIG_ALLOC "Allow unit-tests to use > 1 GB of memory" ON) if (BUILD_TESTING) - find_package(cmocka CONFIG) - if (TARGET cmocka::cmocka) - set(CMOCKA_LIBRARIES cmocka::cmocka) - else () - pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) - set(CMOCKA_LIBRARIES PkgConfig::cmocka) - endif () - set(unit_tests "test_argv" "test_auth_token"
config.h.cmake.in +3 -0
@@ -86,6 +86,9 @@ /* git version information in config-version.h */ #cmakedefine HAVE_CONFIG_VERSION_H +/* cmocka version information available in cmocka_version.h (>= 2.0.0) */ +#cmakedefine HAVE_CMOCKA_VERSION_H + /* Define to 1 if you have the `daemon' function. */ #cmakedefine HAVE_DAEMON
configure.ac +10 -1
@@ -1415,7 +1415,16 @@ [have_cmocka="yes"], [AC_MSG_WARN([cmocka.pc not found on the system using pkg-config ${pkg_config_found}. Unit tests disabled])] ) -AM_CONDITIONAL([ENABLE_UNITTESTS], [test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes" ]) +AM_CONDITIONAL([ENABLE_UNITTESTS], [false]) +if test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes"; then + AM_CONDITIONAL([ENABLE_UNITTESTS], [true]) + + saved_CFLAGS="${CFLAGS}" + CFLAGS="${CFLAGS} ${CMOCKA_CFLAGS}" + # detect cmocka < 2.0.0 that had no cmocka_version.h + AC_CHECK_HEADERS([cmocka_version.h]) + CFLAGS="${saved_CFLAGS}" +fi AC_SUBST([ENABLE_UNITTESTS]) TEST_LDFLAGS="${OPTIONAL_CRYPTO_LIBS} ${OPTIONAL_PKCS11_HELPER_LIBS} ${OPTIONAL_LIBCAPNG_LIBS}"
tests/unit_tests/openvpn/test_common.h +21 -0
@@ -24,6 +24,27 @@#include <setjmp.h> #include <cmocka.h> +/* Do we use cmocka < 2.0.0? */ +#ifndef HAVE_CMOCKA_VERSION_H +#define HAVE_OLD_CMOCKA_API 1 +/* compat with various versions of cmocka.h +* Older versions have LargestIntegralType. Newer +* versions use uintmax_t. But LargestIntegralType +* is not guaranteed to be equal to uintmax_t, so +* we can't use that unconditionally. So we only use +* it if cmocka.h does not define LargestIntegralType. +*/ +#ifndef LargestIntegralType +#define LargestIntegralType uintmax_t +#endif +/* redefine 2.x API in terms of 1.x API */ +#define CMockaValueData LargestIntegralType +#define check_expected_uint check_expected +#define expect_uint_value expect_value +#define expect_check_data expect_check +#define cast_ptr_to_cmocka_value (x) (x) +#endif +/** * Sets up the environment for unit tests like making both stderr and stdout * non-buffered to avoid messages getting lost if the program exits early.
tests/unit_tests/openvpn/test_options_parse.c +31 -35
103 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +1 -1
@@ -171,7 +171,7 @@bool send_control_channel_string (struct context *c,const char *str,msglvl_t msglevel) { -check_expected (str); +check_expected_ptr (str);return true; }
tests/unit_tests/openvpn/test_user_pass.c +1 -1
@@ -52,7 +52,7 @@/* Loop through configured query_user slots */ for (int i =0 ; i <QUERY_USER_NUMSLOTS && query_user[i].response !=NULL ; i++) { -check_expected (query_user[i].prompt); +check_expected_ptr (query_user[i].prompt); strncpy(query_user[i].response, mock_ptr_type(char *), query_user[i].response_len); }
[Openvpn-devel] [PATCH applied] Re: tests/unit_tests: Port to cmocka 2.0.0 API
Looked at the code change - looks reasonable, and makes the unit tests build (with "-Werror") on GHA macOS builders with upgraded cmocka again (and everything still builds and passes UTs on older library versions, verified by GHA and BB).
We also got a LGTM from Chosi on IRC :-)
Git complained about trailing whitespace in CMakeLists.txt (and fixed it). My understanding of CMake is that this should be correct.
Your patch has been applied to the master branch.
It will not "just cherrypick" back to release/2.6, as many of the affected source lines are not there yet - but GHA tells me "we do not exercise any of the warning-inducing functions yet", so we don't need it (yet) either.
commit 6db186e0b1d9783ea96e8a945a47fd23b45e4778
Author: Frank Lichtenheld Date: Thu Dec 18 11:40:32 2025 +0100
tests/unit_tests: Port to cmocka 2.0.0 API
Signed-off-by: Frank Lichtenheld <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1449
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35144.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#4) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: tests/unit_tests: Port to cmocka 2.0.0 API
......................................................................
tests/unit_tests: Port to cmocka 2.0.0 API
But add compat layer so that we can still build
against older versions of cmocka. Mostly this is
trivial but the custom check function changed its
prototype, so that requires some more work.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1449
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35144.html
---
M CMakeLists.txt
M config.h.cmake.in
M configure.ac
M tests/unit_tests/openvpn/test_common.h
M tests/unit_tests/openvpn/test_options_parse.c
M tests/unit_tests/openvpn/test_push_update_msg.c
M tests/unit_tests/openvpn/test_user_pass.c
7 files changed, 79 insertions(+), 46 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/49/1449/4
CMakeLists.txt +12 -8
@@ -379,6 +379,18 @@ ) set(HAVE_CONFIG_VERSION_H YES) +if (BUILD_TESTING) + find_package(cmocka CONFIG) + if (TARGET cmocka::cmocka) + set(CMOCKA_LIBRARIES cmocka::cmocka) + else () + pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) + set(CMOCKA_LIBRARIES PkgConfig::cmocka) + endif () + set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES}) + check_include_files(cmocka_version.h HAVE_CMOCKA_VERSION_H) +endif () + configure_file(config.h.cmake.in config.h) configure_file(include/openvpn-plugin.h.in openvpn-plugin.h) # TODO we should remove the need for this, and always include config.h
@@ -636,14 +648,6 @@ option(UT_ALLOW_BIG_ALLOC "Allow unit-tests to use > 1 GB of memory" ON) if (BUILD_TESTING) - find_package(cmocka CONFIG) - if (TARGET cmocka::cmocka) - set(CMOCKA_LIBRARIES cmocka::cmocka) - else () - pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) - set(CMOCKA_LIBRARIES PkgConfig::cmocka) - endif () - set(unit_tests "test_argv" "test_auth_token"
config.h.cmake.in +3 -0
@@ -86,6 +86,9 @@ /* git version information in config-version.h */ #cmakedefine HAVE_CONFIG_VERSION_H +/* cmocka version information available in cmocka_version.h (>= 2.0.0) */ +#cmakedefine HAVE_CMOCKA_VERSION_H + /* Define to 1 if you have the `daemon' function. */ #cmakedefine HAVE_DAEMON
configure.ac +10 -1
@@ -1415,7 +1415,16 @@ [have_cmocka="yes"], [AC_MSG_WARN([cmocka.pc not found on the system using pkg-config ${pkg_config_found}. Unit tests disabled])] ) -AM_CONDITIONAL([ENABLE_UNITTESTS], [test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes" ]) +AM_CONDITIONAL([ENABLE_UNITTESTS], [false]) +if test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes"; then + AM_CONDITIONAL([ENABLE_UNITTESTS], [true]) + + saved_CFLAGS="${CFLAGS}" + CFLAGS="${CFLAGS} ${CMOCKA_CFLAGS}" + # detect cmocka < 2.0.0 that had no cmocka_version.h + AC_CHECK_HEADERS([cmocka_version.h]) + CFLAGS="${saved_CFLAGS}" +fi AC_SUBST([ENABLE_UNITTESTS]) TEST_LDFLAGS="${OPTIONAL_CRYPTO_LIBS} ${OPTIONAL_PKCS11_HELPER_LIBS} ${OPTIONAL_LIBCAPNG_LIBS}"
tests/unit_tests/openvpn/test_common.h +21 -0
@@ -24,6 +24,27 @@#include <setjmp.h> #include <cmocka.h> +/* Do we use cmocka < 2.0.0? */ +#ifndef HAVE_CMOCKA_VERSION_H +#define HAVE_OLD_CMOCKA_API 1 +/* compat with various versions of cmocka.h +* Older versions have LargestIntegralType. Newer +* versions use uintmax_t. But LargestIntegralType +* is not guaranteed to be equal to uintmax_t, so +* we can't use that unconditionally. So we only use +* it if cmocka.h does not define LargestIntegralType. +*/ +#ifndef LargestIntegralType +#define LargestIntegralType uintmax_t +#endif +/* redefine 2.x API in terms of 1.x API */ +#define CMockaValueData LargestIntegralType +#define check_expected_uint check_expected +#define expect_uint_value expect_value +#define expect_check_data expect_check +#define cast_ptr_to_cmocka_value (x) (x) +#endif +/** * Sets up the environment for unit tests like making both stderr and stdout * non-buffered to avoid messages getting lost if the program exits early.
tests/unit_tests/openvpn/test_options_parse.c +31 -35
103 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +1 -1
@@ -171,7 +171,7 @@bool send_control_channel_string (struct context *c,const char *str,msglvl_t msglevel) { -check_expected (str); +check_expected_ptr (str);return true; }
tests/unit_tests/openvpn/test_user_pass.c +1 -1
@@ -52,7 +52,7 @@/* Loop through configured query_user slots */ for (int i =0 ; i <QUERY_USER_NUMSLOTS && query_user[i].response !=NULL ; i++) { -check_expected (query_user[i].prompt); +check_expected_ptr (query_user[i].prompt); strncpy(query_user[i].response, mock_ptr_type(char *), query_user[i].response_len); }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ifb6594700db71d219643a29c581099c778bcbbc6
Gerrit-Change-Number: 1449
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email )
Change subject: tests/unit_tests: Port to cmocka 2.0.0 API
......................................................................
tests/unit_tests: Port to cmocka 2.0.0 API
But add compat layer so that we can still build
against older versions of cmocka. Mostly this is
trivial but the custom check function changed its
prototype, so that requires some more work.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1449
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35144.html
---
M CMakeLists.txt
M config.h.cmake.in
M configure.ac
M tests/unit_tests/openvpn/test_common.h
M tests/unit_tests/openvpn/test_options_parse.c
M tests/unit_tests/openvpn/test_push_update_msg.c
M tests/unit_tests/openvpn/test_user_pass.c
7 files changed, 79 insertions(+), 46 deletions(-)
CMakeLists.txt +12 -8
@@ -379,6 +379,18 @@ ) set(HAVE_CONFIG_VERSION_H YES) +if (BUILD_TESTING) + find_package(cmocka CONFIG) + if (TARGET cmocka::cmocka) + set(CMOCKA_LIBRARIES cmocka::cmocka) + else () + pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) + set(CMOCKA_LIBRARIES PkgConfig::cmocka) + endif () + set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES}) + check_include_files(cmocka_version.h HAVE_CMOCKA_VERSION_H) +endif () + configure_file(config.h.cmake.in config.h) configure_file(include/openvpn-plugin.h.in openvpn-plugin.h) # TODO we should remove the need for this, and always include config.h
@@ -636,14 +648,6 @@ option(UT_ALLOW_BIG_ALLOC "Allow unit-tests to use > 1 GB of memory" ON) if (BUILD_TESTING) - find_package(cmocka CONFIG) - if (TARGET cmocka::cmocka) - set(CMOCKA_LIBRARIES cmocka::cmocka) - else () - pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) - set(CMOCKA_LIBRARIES PkgConfig::cmocka) - endif () - set(unit_tests "test_argv" "test_auth_token"
config.h.cmake.in +3 -0
@@ -86,6 +86,9 @@ /* git version information in config-version.h */ #cmakedefine HAVE_CONFIG_VERSION_H +/* cmocka version information available in cmocka_version.h (>= 2.0.0) */ +#cmakedefine HAVE_CMOCKA_VERSION_H + /* Define to 1 if you have the `daemon' function. */ #cmakedefine HAVE_DAEMON
configure.ac +10 -1
@@ -1415,7 +1415,16 @@ [have_cmocka="yes"], [AC_MSG_WARN([cmocka.pc not found on the system using pkg-config ${pkg_config_found}. Unit tests disabled])] ) -AM_CONDITIONAL([ENABLE_UNITTESTS], [test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes" ]) +AM_CONDITIONAL([ENABLE_UNITTESTS], [false]) +if test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes"; then + AM_CONDITIONAL([ENABLE_UNITTESTS], [true]) + + saved_CFLAGS="${CFLAGS}" + CFLAGS="${CFLAGS} ${CMOCKA_CFLAGS}" + # detect cmocka < 2.0.0 that had no cmocka_version.h + AC_CHECK_HEADERS([cmocka_version.h]) + CFLAGS="${saved_CFLAGS}" +fi AC_SUBST([ENABLE_UNITTESTS]) TEST_LDFLAGS="${OPTIONAL_CRYPTO_LIBS} ${OPTIONAL_PKCS11_HELPER_LIBS} ${OPTIONAL_LIBCAPNG_LIBS}"
tests/unit_tests/openvpn/test_common.h +21 -0
@@ -24,6 +24,27 @@#include <setjmp.h> #include <cmocka.h> +/* Do we use cmocka < 2.0.0? */ +#ifndef HAVE_CMOCKA_VERSION_H +#define HAVE_OLD_CMOCKA_API 1 +/* compat with various versions of cmocka.h +* Older versions have LargestIntegralType. Newer +* versions use uintmax_t. But LargestIntegralType +* is not guaranteed to be equal to uintmax_t, so +* we can't use that unconditionally. So we only use +* it if cmocka.h does not define LargestIntegralType. +*/ +#ifndef LargestIntegralType +#define LargestIntegralType uintmax_t +#endif +/* redefine 2.x API in terms of 1.x API */ +#define CMockaValueData LargestIntegralType +#define check_expected_uint check_expected +#define expect_uint_value expect_value +#define expect_check_data expect_check +#define cast_ptr_to_cmocka_value (x) (x) +#endif +/** * Sets up the environment for unit tests like making both stderr and stdout * non-buffered to avoid messages getting lost if the program exits early.
tests/unit_tests/openvpn/test_options_parse.c +31 -35
103 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +1 -1
@@ -171,7 +171,7 @@bool send_control_channel_string (struct context *c,const char *str,msglvl_t msglevel) { -check_expected (str); +check_expected_ptr (str);return true; }
tests/unit_tests/openvpn/test_user_pass.c +1 -1
@@ -52,7 +52,7 @@/* Loop through configured query_user slots */ for (int i =0 ; i <QUERY_USER_NUMSLOTS && query_user[i].response !=NULL ; i++) { -check_expected (query_user[i].prompt); +check_expected_ptr (query_user[i].prompt); strncpy(query_user[i].response, mock_ptr_type(char *), query_user[i].response_len); }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1449?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ifb6594700db71d219643a29c581099c778bcbbc6
Gerrit-Change-Number: 1449
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>